#include "registers.h"

struct reg
{
	char *name;
	int code;
};

static word registers [16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

static struct reg codes [17] = 
{
	{"$zero", ZERO},
	{"$flag", FLAG},
	{"$ra", RA},
	{"$rv", RV},
	{"$g0", G0},
	{"$g1", G1},
	{"$g2", G2},
	{"$g3", G3},
	{"$g4", G4},
	{"$g5", G5},
	{"$g6", G6},
	{"$t0", T0},
	{"$t1", T1},
	{"$t2", T2},
	{"$t3", T3},
	{"$sp", SP},
	{0, 0}
};


word get_register (word reg)
{
	reg = reg & 0xF;
	if (reg)
	{
		return registers [reg];
	}
	return 0;
}

void set_register (word reg, word data)
{
	reg = reg & 0xF;
	if (reg)
	{
		registers [reg] = data;
	}
}

int lookup_register (char *name)
{
	int i;
	for (i = 0; codes [i].name; i ++)
	{
		if (! strcasecmp (name, codes [i].name))
		{
			return codes [i].code;
		}
	}
	return -1;
}

#if 0
void dump_registers (void)
{
	int i;
	char buf [32];
	for (i = 0; i < 16; i ++)
	{
		sprintf (buf, "%s:%d ", codes [i].name + 1, registers [i]);
		tty_puts (buf);
	}
	tty_putc ('\n');
}
#endif

